﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;
using System.Globalization;

namespace BLL.DutyAssignment
{
    public class B_DutyDetail
    {
        private readonly OracleDAL.DutyAssignment.D_DutyDetail dal = new OracleDAL.DutyAssignment.D_DutyDetail();

        /// <summary>
		/// 得到一个对象实体
		/// </summary>
        public Model.DutyAssignment.M_DutyDetail GetModel(string ID)
        {
            return dal.GetModel(ID);
        }

        /// <summary>
		///  增加一条数据
		/// </summary>
        public bool Add(Model.DutyAssignment.M_DutyDetail model)
        {
            return dal.Add(model);
        }

        /// <summary>
		///  更新一条数据
		/// </summary>
        public bool Update(Model.DutyAssignment.M_DutyDetail model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string strWhere)
        {
            return dal.Delete(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        public string GetHoliday(DateTime time)
        {
            ChineseLunisolarCalendar ChineseDate = new ChineseLunisolarCalendar();
            if (time.DayOfYear == 1)
            {
                return "元旦";
            }
            else if (ChineseDate.GetMonth(time) == 1 && ChineseDate.GetDayOfMonth(time) == 1)
            {
                return "春节";
            }
            else if (ChineseDate.GetMonth(time) == 1 && ChineseDate.GetDayOfMonth(time) == 2)
            {
                return "法定节假日";
            }
            else if (ChineseDate.GetMonth(time) == 1 && ChineseDate.GetDayOfMonth(time) == 3)
            {
                return "法定节假日";
            }
            else if ((ChineseDate.IsLeapYear(time.Year) && ChineseDate.GetLeapMonth(time.Year) <= 5 && ChineseDate.GetMonth(time) == 6 && ChineseDate.GetDayOfMonth(time) == 5) || (ChineseDate.IsLeapYear(time.Year) && ChineseDate.GetLeapMonth(time.Year) > 5 && ChineseDate.GetMonth(time) == 5 && ChineseDate.GetDayOfMonth(time) == 5) || (!ChineseDate.IsLeapYear(time.Year) && ChineseDate.GetMonth(time) == 5 &&ChineseDate.GetDayOfMonth(time) == 5))
            {
                return "端午节";
            }
            else if (time.ToString().Split(' ')[0] == "2009-4-4" || time.ToString().Split(' ')[0] == "2010-4-4" || time.ToString().Split(' ')[0] == "2011-4-5" || time.ToString().Split(' ')[0] == "2012-4-4" || time.ToString().Split(' ')[0] == "2013-4-4" || time.ToString().Split(' ')[0] == "2014-4-5" || time.ToString().Split(' ')[0] == "2015-4-5" || time.ToString().Split(' ')[0] == "2016-4-4" || time.ToString().Split(' ')[0] == "2017-4-4" || time.ToString().Split(' ')[0] == "2018-4-5" || time.ToString().Split(' ')[0] == "2019-4-5" || time.ToString().Split(' ')[0] == "2020-4-4")
            {
                return "清明节";
            }
            else if (time.Month == 5 && time.Day == 1)
            {
                return "五一劳动节";
            }
            else if (time.Month == 7 && time.Day == 1)
            {
                return "建党节";
            }
            else if (time.Month == 8 && time.Day == 1)
            {
                return "建军节";
            }

            else if ((ChineseDate.IsLeapYear(time.Year) && ChineseDate.GetLeapMonth(time.Year) <= 8 && ChineseDate.GetMonth(time) == 9 && ChineseDate.GetDayOfMonth(time) == 15) || (ChineseDate.IsLeapYear(time.Year) && ChineseDate.GetLeapMonth(time.Year) > 8 && ChineseDate.GetMonth(time) == 8 && ChineseDate.GetDayOfMonth(time) == 15) || (!ChineseDate.IsLeapYear(time.Year) && ChineseDate.GetMonth(time) == 8 && ChineseDate.GetDayOfMonth(time) == 15))
            {
                return "中秋节";
            }

            else if (time.Month == 10 && time.Day == 1)
            {
                return "国庆节";
            }
            else if (time.Month == 10 && (time.Day == 2 || time.Day == 3))
            {
                return "法定节假日";
            }
            else
            {
                string str = GetWeek(time);
                return str;
            }
        }

        public string GetWeek(DateTime time)
        {
            if (time.DayOfWeek.ToString() == "Saturday" || time.DayOfWeek.ToString() == "Sunday")
            {
                return "周末班";
            }
            else
            {
                return "平常班";
            }
        }

        /// <summary>
        /// 得到统计结果
        /// </summary>
        /// <param name="unitisn"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public DataTable GetStatisticTable(string unitisn, string startTime, string endTime)
        {
            return dal.GetStatisticTable(unitisn, startTime, endTime);
        }
    }
}
